@page "/grid/bookings-auto"
@attribute [Authorize(Roles = "Employee")]
@inject IJSRuntime JS

<Breadcrumbs class="mb-8">
    <Breadcrumb href="/grid">
        AutoQuery APIs
    </Breadcrumb>
    <Breadcrumb>
        Bookings Auto Columns
    </Breadcrumb>
</Breadcrumbs>

<AutoQueryGrid Model="Booking" Apis="Apis.AutoQuery<QueryBookings,CreateBooking,UpdateBooking,DeleteBooking>()"
               AllowSelection="true" AllowFiltering="true"
               HeaderSelected="OnSelectedHeader" RowSelected="OnSelectedRow">
</AutoQueryGrid>

<ExampleCode Title="Source Code" Path="/AutoQueryGrids/BookingsAuto.razor" />

@code {
    string FormatDate(object o) => o is DateTime d ? d.ToShortDateString() : "";

    // Handle when table header is selected
    public async Task OnSelectedHeader(Column<Booking> item)
    {
        await JS.Log(item.Name);
    }

    // Handle when table row is selected
    public async Task OnSelectedRow(Booking? x)
    {
        var wasDeselected = x == null;
        if (!wasDeselected) await JS.Log($"{x.Name}");
    }
}
